package com.lemon.smartsafety.ui.fragment.fire.situation;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.ldzs.recyclerlibrary.view.FullyGridLayoutManager;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.entity.safe.company.FloorNumItem;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.activity.fire.item.inspection.FireInspectionBuildItemActivity;
import com.lemon.smartsafety.ui.adapter.safe.data.BuildingFloorAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BaseFragment;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.smartsafety.utils.common.ViewUtils;

import java.util.List;

import butterknife.Bind;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/9/9 16:15
 * 修改人：Fargo
 * 修改时间：2016/9/9 16:15
 * 修改备注：
 */
public class FireInspectionBuildingFloorFragment extends BaseFragment implements RecyclerTClickListener<FloorNumItem> {
    private LoggerHelper loggerHelper = new LoggerHelper(FireInspectionBuildingFloorFragment.class);
    private List<FloorNumItem> floorNumItems;

    private int columnNumbers = 4;
    /** 是否是安全巡查界面过来的 */
    private boolean isSafeInspection = false;

    public static FireInspectionBuildingFloorFragment newInstance() {
        FireInspectionBuildingFloorFragment fragment = new FireInspectionBuildingFloorFragment();
        return fragment;
    }

    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private BuildingFloorAdapter mFloorAdapter;


    @Override
    protected void getBaseArguments() {
        if (getArguments() != null) {
            floorNumItems = (List<FloorNumItem>) getArguments().getSerializable(BundleKey.COMPANY_BUILDING_FLOOR_NUMBERS);
            isSafeInspection = getArguments().getBoolean(BundleKey.IS_SAFE_INSPECTION,false);
        }
        int screenWidth = ViewUtils.getScreenWidth(IApplication.context());
        int itemHeight = ViewUtils.dip2px(IApplication.context(), 48);
        columnNumbers = screenWidth / itemHeight;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.view_recycler_view;
    }

    @Override
    protected void initViews() {
        FullyGridLayoutManager gridLayoutManager = new FullyGridLayoutManager(getContext(), columnNumbers);
        gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
        gridLayoutManager.setSmoothScrollbarEnabled(true);
        mRecyclerView.setLayoutManager(gridLayoutManager);
        mRecyclerView.setNestedScrollingEnabled(false);
        mFloorAdapter = new BuildingFloorAdapter(floorNumItems, this, isSafeInspection);
        mRecyclerView.setAdapter(mFloorAdapter);
    }

    @Override
    public void onItemClick(FloorNumItem data, int position) {
//        FloorNumItemEvent event = new FloorNumItemEvent();
//        event.setTag(FloorNumItemEvent.class.getName());
//        event.setPosition(position);
//        event.setData(data);
//        AppService.getBus().post(event);

        ((FireInspectionBuildItemActivity) getActivity()).getNetData(data.getItemTitle());
    }



}
